package com.playball.lottery.frm.buyhall;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.Html;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.playball.lottery.R;
import com.playball.lottery.ApplicationData;
import com.playball.lottery.JddMainActivity;
import com.playball.lottery.base.BaseActivity;
import com.playball.lottery.customview.BallDTO;
import com.playball.lottery.customview.MyDialog;
import com.playball.lottery.frm.help.CaiPiaoHelp;
import com.playball.lottery.frm.kjinfo.KjinfoListByType;
import com.playball.lottery.frm.yhzx.BetRecordActivity;
import com.playball.lottery.frm.yhzx.LoginActivity;
import com.playball.lottery.frm.yhzx.ZhRecordActivity;
import com.playball.lottery.nt.GetRequestParams;
import com.playball.lottery.util.ConvertJsonToList;
import com.playball.lottery.util.DefConstants;
import com.playball.lottery.util.DynArrayInt;
import com.playball.lottery.util.FactoryNum;
import com.playball.lottery.util.Kuai3Util;
import com.playball.lottery.util.SensorListener;
import com.playball.lottery.util.SoundManage;
import com.playball.lottery.util.SysApplication;


/**
 * 
 * 11运夺金购彩选号
 * 
 */
public class ElvYunDJActivity extends BaseActivity implements Serializable, DefConstants {
	/** 上下文内容 */
	private Context context = null;
	private static final long serialVersionUID = 1L;
	public Button imButton01, imButton02, imButton03, imButton04, imButton05, imButton06, imButton07, imButton08,
			imButton09, imButton10, imButton11;
	public Button imButtonb_01, imButtonb_02, imButtonb_03, imButtonb_04, imButtonb_05, imButtonb_06, imButtonb_07,
			imButtonb_08, imButtonb_09, imButtonb_10, imButtonb_11, imButtonc_01, imButtonc_02, imButtonc_03,
			imButtonc_04, imButtonc_05, imButtonc_06, imButtonc_07, imButtonc_08, imButtonc_09, imButtonc_10,
			imButtonc_11;
	private LinearLayout buy_11x5_first_num, buy_11x5_2nd_num, buy_11x5_3rd_num, buy_11x5_first_text_layout;
	/** 任选x说明：至少选x个号码 */
	private LinearLayout buy_11x5_1st_llnote;// 任选说明：至少选x个号码
	/** 直选2,3中间分割线 */
	private View buy_23_line;
	private Button buy_11x5_random;// 机选红球
	private Button buy_11x5_clear;// 清空选择
	private Button buy_11x5_submit;// 确认选择
	/** 任选x说明：至少选x个号码 */
	private TextView buy_11x5_1st_tvnote;
	private TextView currentIssue;// 当前期次
	private TextView endTimeText;// 截至时间
	private TextView countText;// 倍数
	private TextView moneyText;
	private String strPlayType = "任选五";
	private int lotID;
	private long endTime; // 剩余时间
	private int playTypeId = 6205;
	private int count;
	private int allMoney;
	private String issueID; // 当前期次编号
	private String issueName;
	private PopupWindow m_popupWindow;
	/** 菜单弹出框 */
	private PopupWindow menu_popupWindow;
	/** 菜单弹出框 */
	private View menutypeview;
	boolean flag = false;
	private DynArrayInt ball_1st_dintInt;
	private DynArrayInt ball_2nd_dintInt;
	private DynArrayInt ball_3rd_dintInt;
	Handler handler = new Handler();
	private SensorListener sensor;
	/** .若中奖：奖金0彩豆，盈利0彩豆 */
	private TextView tvJiangJin;
	/** 摇一摇机选一注视图 */
	private LinearLayout buy_ssq_llfoot0;
	/** 注数金额 */
	private RelativeLayout buy_ssq_rlfoot1;
	/** 点击此处可以弹出下拉10期开奖 */
	private LinearLayout buy_ssqxh_llxiala;
	/** 下拉10期开奖详情 */
	private LinearLayout buy_ssqxh_ll10kjdetail;
	/** 下拉10期开奖详情 */
	private List<Map<String, Object>> kjData;

	/** 奖金 */
	private int prizeIntellChase;

	/** 判断是否从选号列表过来 */
	private Boolean ifbacklist;
	/** 判断是否从推送通知过来 */
	private Boolean ifPush;
	private LinearLayout buy_ssqxh_Button03,buy_ssqxh_Button04;

	/**
	 * 已保存的倍数
	 */
	int bs = 1;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.context = this;
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.buy_11x5);
		SysApplication.getInstance().addActivity(this);
		TitleBar();

		kaijiangAsyncLoader task = new kaijiangAsyncLoader();
		task.execute(LOT_ID_11YDJ + "", "301");

		Intent intent = getIntent();
		lotID = LOT_ID_11YDJ;
		issueID = intent.getStringExtra("IssueID");
		issueName = intent.getStringExtra("IssueName");
		endTime = intent.getLongExtra("EndTime", 0);
		ifbacklist = intent.getBooleanExtra("ifbacklist", false);
		ifPush = intent.getBooleanExtra("ifPush", false);
		bs = intent.getIntExtra("bs", 1);
		playTypeId = intent.getIntExtra("playTypeId", 6205);
		if (playTypeId == 6201) {
			strPlayType = "任选一";
		} else if (playTypeId == 6202) {
			strPlayType = "任选二";
		} else if (playTypeId == 6203) {
			strPlayType = "任选三";
		} else if (playTypeId == 6204) {
			strPlayType = "任选四";
		} else if (playTypeId == 6205) {
			strPlayType = "任选五";
		} else if (playTypeId == 6206) {
			strPlayType = "任选六";
		} else if (playTypeId == 6207) {
			strPlayType = "任选七";
		} else if (playTypeId == 6208) {
			strPlayType = "任选八";
		} else if (playTypeId == 6209) {
			strPlayType = "前二直选";
		} else if (playTypeId == 6210) {
			strPlayType = "前三直选";
		} else if (playTypeId == 6211) {
			strPlayType = "前二组选";
		} else if (playTypeId == 6212) {
			strPlayType = "前三组选";
		}
		initView();

		currentIssue.setText(issueName);

		handler.postDelayed(runnable, 1000);

		AsyncLoader task1 = new AsyncLoader();
		String[] parms = new String[2];
		parms[0] = "200";
		JSONObject jsob = new JSONObject();
		try {
			// 设置请求所需参数
			jsob.put("LottID", LOT_ID_11YDJ);
			parms[1] = jsob.toString();
			task1.execute(parms);
		} catch (JSONException ex) {
			// TODO Auto-generated catch block
			Log.e("error", ex.toString());
		}

		// 下拉10期开奖
		buy_ssqxh_llxiala.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				doKaiJiang();
			}
		});

		buy_ssqxh_ll10kjdetail.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (buy_ssqxh_ll10kjdetail.getVisibility() == View.VISIBLE) {
					buy_ssqxh_ll10kjdetail.setVisibility(View.GONE);
				}
			}
		});

		// 清空选择
		buy_11x5_clear.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (ball_1st_dintInt.getSize() != 0) {
					initBall();
					allMoney = 0;
					count = 0;
					moneyText.setText("0");
					countText.setText("0");
					tvJiangJin.setText(context.getString(R.string.buy_show_jiangjin));
					buy_ssq_llfoot0.setVisibility(View.VISIBLE);
					buy_ssq_rlfoot1.setVisibility(View.GONE);
				} else {
					Toast.makeText(ElvYunDJActivity.this, R.string.number_did_not_choose, Toast.LENGTH_SHORT).show();
					initBall();
				}
			}
		});

		// 晃动手机机选号码
		sensor = new SensorListener(this);
		sensor.setOnSensorListener(new SensorListener.OnSensorListener() {
			@Override
			public void onShake() {
				// TODO Auto-generated method stub
				SoundManage.OnVibator(ElvYunDJActivity.this, 500);
				initRandomBall();
				// SoundManage.OnPlaySound(SsqxhActivity.this, "audio.mp3");
			}
		});

		// 机选
		buy_11x5_random.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				initRandomBall();
			}
		});

		// 确认选择，跳转至ElvSelFiveListbActivity.class
		buy_11x5_submit.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				
				goXhlbSubmit();
			}
		});

		if(!ifbacklist){
			initRandomBall();
		}
	}

	/**
	 * 开奖栏点击 事件
	 */
	protected void doKaiJiang() {
		if (kjData != null && buy_ssqxh_ll10kjdetail.getVisibility() == View.GONE) {
			buy_ssqxh_ll10kjdetail.setVisibility(View.VISIBLE);
			TextView buy_ssq_10qikj_tvqici1 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici1);
			TextView buy_ssq_10qikj_tvqici2 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici2);
			TextView buy_ssq_10qikj_tvqici3 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici3);
			TextView buy_ssq_10qikj_tvqici4 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici4);
			TextView buy_ssq_10qikj_tvqici5 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici5);
			TextView buy_ssq_10qikj_tvqici6 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici6);
			TextView buy_ssq_10qikj_tvqici7 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici7);
			TextView buy_ssq_10qikj_tvqici8 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici8);
			TextView buy_ssq_10qikj_tvqici9 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici9);
			TextView buy_ssq_10qikj_tvqici10 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvqici10);

			TextView buy_ssq_10qikj_tvred1 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred1);
			TextView buy_ssq_10qikj_tvred2 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred2);
			TextView buy_ssq_10qikj_tvred3 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred3);
			TextView buy_ssq_10qikj_tvred4 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred4);
			TextView buy_ssq_10qikj_tvred5 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred5);
			TextView buy_ssq_10qikj_tvred6 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred6);
			TextView buy_ssq_10qikj_tvred7 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred7);
			TextView buy_ssq_10qikj_tvred8 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred8);
			TextView buy_ssq_10qikj_tvred9 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred9);
			TextView buy_ssq_10qikj_tvred10 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvred10);

			TextView buy_ssq_10qikj_tvblue1 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue1);
			TextView buy_ssq_10qikj_tvblue2 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue2);
			TextView buy_ssq_10qikj_tvblue3 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue3);
			TextView buy_ssq_10qikj_tvblue4 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue4);
			TextView buy_ssq_10qikj_tvblue5 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue5);
			TextView buy_ssq_10qikj_tvblue6 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue6);
			TextView buy_ssq_10qikj_tvblue7 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue7);
			TextView buy_ssq_10qikj_tvblue8 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue8);
			TextView buy_ssq_10qikj_tvblue9 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue9);
			TextView buy_ssq_10qikj_tvblue10 = (TextView) findViewById(R.id.buy_ssq_10qikj_tvblue10);

			if (kjData != null && kjData.size() > 0) {
				buy_ssq_10qikj_tvqici1.setText(kjData.get(0).get("Issue").toString());
				buy_ssq_10qikj_tvred1.setText(kjData.get(0).get("Ball").toString());
				if (kjData.size() > 1) {
					buy_ssq_10qikj_tvqici2.setText(kjData.get(1).get("Issue").toString());
					buy_ssq_10qikj_tvred2.setText(kjData.get(1).get("Ball").toString());
				}
				if (kjData.size() > 2) {
					buy_ssq_10qikj_tvqici3.setText(kjData.get(2).get("Issue").toString());
					buy_ssq_10qikj_tvred3.setText(kjData.get(2).get("Ball").toString());
				}
				if (kjData.size() > 3) {
					buy_ssq_10qikj_tvqici4.setText(kjData.get(3).get("Issue").toString());
					buy_ssq_10qikj_tvred4.setText(kjData.get(3).get("Ball").toString());
				}
				if (kjData.size() > 4) {
					buy_ssq_10qikj_tvqici5.setText(kjData.get(4).get("Issue").toString());
					buy_ssq_10qikj_tvred5.setText(kjData.get(4).get("Ball").toString());
				}
				if (kjData.size() > 5) {
					buy_ssq_10qikj_tvqici6.setText(kjData.get(5).get("Issue").toString());
					buy_ssq_10qikj_tvred6.setText(kjData.get(5).get("Ball").toString());
				}
				if (kjData.size() > 6) {
					buy_ssq_10qikj_tvqici7.setText(kjData.get(6).get("Issue").toString());
					buy_ssq_10qikj_tvred7.setText(kjData.get(6).get("Ball").toString());
				}
				if (kjData.size() > 7) {
					buy_ssq_10qikj_tvqici8.setText(kjData.get(7).get("Issue").toString());
					buy_ssq_10qikj_tvred8.setText(kjData.get(7).get("Ball").toString());
				}
				if (kjData.size() > 8) {
					buy_ssq_10qikj_tvqici9.setText(kjData.get(8).get("Issue").toString());
					buy_ssq_10qikj_tvred9.setText(kjData.get(8).get("Ball").toString());
				}
				if (kjData.size() > 9) {
					buy_ssq_10qikj_tvqici10.setText(kjData.get(9).get("Issue").toString());
					buy_ssq_10qikj_tvred10.setText(kjData.get(9).get("Ball").toString());
				}

				if (kjData.get(0).get("BlueBall") != null && !"".equals(kjData.get(0).get("BlueBall").toString())) {
					buy_ssq_10qikj_tvblue1.setText(kjData.get(0).get("BlueBall").toString());
					if (kjData.size() > 1) {
						buy_ssq_10qikj_tvblue2.setText(kjData.get(1).get("BlueBall").toString());
					}
					if (kjData.size() > 2) {
						buy_ssq_10qikj_tvblue3.setText(kjData.get(2).get("BlueBall").toString());
					}
					if (kjData.size() > 3) {
						buy_ssq_10qikj_tvblue4.setText(kjData.get(3).get("BlueBall").toString());
					}
					if (kjData.size() > 4) {
						buy_ssq_10qikj_tvblue5.setText(kjData.get(4).get("BlueBall").toString());
					}
					if (kjData.size() > 5) {
						buy_ssq_10qikj_tvblue6.setText(kjData.get(5).get("BlueBall").toString());
					}
					if (kjData.size() > 6) {
						buy_ssq_10qikj_tvblue7.setText(kjData.get(6).get("BlueBall").toString());
					}
					if (kjData.size() > 7) {
						buy_ssq_10qikj_tvblue8.setText(kjData.get(7).get("BlueBall").toString());
					}
					if (kjData.size() > 8) {
						buy_ssq_10qikj_tvblue9.setText(kjData.get(8).get("BlueBall").toString());
					}
					if (kjData.size() > 9) {
						buy_ssq_10qikj_tvblue10.setText(kjData.get(9).get("BlueBall").toString());
					}
				} else {
					TextView buy_10qikj_tvfh1 = (TextView) findViewById(R.id.buy_10qikj_tvfh1);
					TextView buy_10qikj_tvfh2 = (TextView) findViewById(R.id.buy_10qikj_tvfh2);
					TextView buy_10qikj_tvfh3 = (TextView) findViewById(R.id.buy_10qikj_tvfh3);
					TextView buy_10qikj_tvfh4 = (TextView) findViewById(R.id.buy_10qikj_tvfh4);
					TextView buy_10qikj_tvfh5 = (TextView) findViewById(R.id.buy_10qikj_tvfh5);
					TextView buy_10qikj_tvfh6 = (TextView) findViewById(R.id.buy_10qikj_tvfh6);
					TextView buy_10qikj_tvfh7 = (TextView) findViewById(R.id.buy_10qikj_tvfh7);
					TextView buy_10qikj_tvfh8 = (TextView) findViewById(R.id.buy_10qikj_tvfh8);
					TextView buy_10qikj_tvfh9 = (TextView) findViewById(R.id.buy_10qikj_tvfh9);
					TextView buy_10qikj_tvfh10 = (TextView) findViewById(R.id.buy_10qikj_tvfh10);
					buy_10qikj_tvfh1.setVisibility(View.GONE);
					buy_10qikj_tvfh2.setVisibility(View.GONE);
					buy_10qikj_tvfh3.setVisibility(View.GONE);
					buy_10qikj_tvfh4.setVisibility(View.GONE);
					buy_10qikj_tvfh5.setVisibility(View.GONE);
					buy_10qikj_tvfh6.setVisibility(View.GONE);
					buy_10qikj_tvfh7.setVisibility(View.GONE);
					buy_10qikj_tvfh8.setVisibility(View.GONE);
					buy_10qikj_tvfh9.setVisibility(View.GONE);
					buy_10qikj_tvfh10.setVisibility(View.GONE);

					buy_ssq_10qikj_tvblue1.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue1.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue2.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue3.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue4.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue5.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue6.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue7.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue8.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue9.setVisibility(View.GONE);
					buy_ssq_10qikj_tvblue10.setVisibility(View.GONE);
				}
			}
		} else {
			buy_ssqxh_ll10kjdetail.setVisibility(View.GONE);
		}
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		sensor.stop();
		
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		sensor.start();
		
	}

	public void sendIntent(BallDTO elvdto, String ball) {
		elvdto.setElv_ball(ball + "-" + allMoney);

		// 新选的号码，追加在ApplicationBall全局变量list_ssqdto里
		ApplicationData.getInstance().getList_11x5dto().add(elvdto);
		ApplicationData.getInstance().setAll_11x5money(ApplicationData.getInstance().getAll_11x5money() + allMoney);
		ApplicationData.getInstance().setPlay_11x5Id(playTypeId);

		Intent intent = new Intent();
		intent.putExtra("list_elvdto", ApplicationData.getInstance().getList_11x5dto());
		intent.putExtra("PlayTypeID", playTypeId);
		intent.putExtra("PlayType", strPlayType);
		intent.putExtra("AllMoney", ApplicationData.getInstance().getAll_11x5money());
		intent.putExtra("LotID", lotID);
		intent.putExtra("Count", count);
		intent.putExtra("IssueID", issueID);
		intent.putExtra("IssueName", issueName);
		intent.putExtra("bs", bs);
		intent.putExtra("prizeIntellChase", prizeIntellChase);
		intent.setClass(ElvYunDJActivity.this, ElvYunDJListActivity.class);
		startActivityForResult(intent, REQ_CODE_BUYMAIN);// (intent);
		finish();
	}

	// 倒计时
	Runnable runnable = new Runnable() {
		@Override
		public void run() {
			getCountDown(endTime--);
			handler.postDelayed(this, 1000);
		}
	};

	private void getCountDown(long end) {
		if (end > 0) {
			String res = "";
			long temp = 0;
			long d = end / 86400;
			temp = end - (d * 86400);
			if (d > 0) {
				res += d + "天";
			}

			long h = temp / 3600;
			if (h > 0) {
				res += h + "时";
			}
			temp = temp - (h * 3600);

			long m = temp / 60;
			if (m > 0) {
				res += m + "分";
			}
			temp = temp - (m * 60);

			long s = temp;
			res += s + "秒";
			endTimeText.setText(res);
		} else {
			endTimeText.setText("----------");
			// AsyncLoader task = new AsyncLoader();
			// task.execute("206");
			AsyncLoader task = new AsyncLoader();
			String[] parms = new String[2];
			parms[0] = "200";
			JSONObject jsob = new JSONObject();
			try {
				// 设置请求所需参数
				jsob.put("LottID", LOT_ID_11YDJ);
				parms[1] = jsob.toString();
				task.execute(parms);
			} catch (JSONException ex) {
				// TODO Auto-generated catch block
				Log.e("error", ex.toString());
			}
		}
	}

	private List<Map<String, Object>> mData;
	private Map<String, Object> cData;

	/**
	 * 获取截止时间
	 * 
	 * @author
	 * 
	 */
	class AsyncLoader extends AsyncTask<String, Integer, String> {// 继承AsyncTask
		int id;

		// 1.准备运行
		protected void onPreExecute() {
		}

		// 2.正在后台运行
		@Override
		protected String doInBackground(String... params) {
			// 处理后台执行的任务，在后台线程执行
			String strResult;
			// String param = new String();
			// 设置请求action
			String action = params[0];
			// 获取请求返回值
			strResult = GetRequestParams.getRequestResult(params[1], action, getApplicationContext());
			return strResult;
		}

		// 3.进度更新
		protected void onProgressUpdate(Integer... progress) {
		}

		// 4.完成后台任务
		protected void onPostExecute(String result) {
			if (result != null) {
				mData = getData(result);
				try {
					JSONTokener jsonParser = new JSONTokener(result);
					JSONObject js = (JSONObject) jsonParser.nextValue();
					// 接下来的就是JSON对象的操作了
					if (Integer.parseInt(js.getString("Code")) == 0) {
						for (int i = 0; i < mData.size(); i++) {
							id = Integer.parseInt(mData.get(i).get("LotID").toString());
							cData = mData.get(i);
							switch (id) {
							case LOT_ID_11YDJ:
								issueID = cData.get("IssueID").toString();
								issueName = cData.get("IssueName").toString();
								endTime = setEndTime(cData);
								currentIssue.setText(issueName);
							}
						}
					} else {
						Toast.makeText(ElvYunDJActivity.this, js.getString("Data"), Toast.LENGTH_SHORT).show();
					}
				} catch (JSONException ex) {
					// 异常处理代码
					Log.e("error", ex.toString());
				}
			} else {
				Toast.makeText(ElvYunDJActivity.this, getString(R.string.problem_01), Toast.LENGTH_LONG).show();
				return;
			}
		}

		// 5.完成后操作
		protected void onCancelled() {
		}
	}

	/**
	 * 
	 * 获取开奖数据
	 * 
	 */
	public class kaijiangAsyncLoader extends AsyncTask<String, Integer, String> {// 继承AsyncTask

		// 1.准备运行
		protected void onPreExecute() {
			// showdialog.showDialog(KjinfoListByType.this);
		}

		// 2.正在后台运行
		@Override
		protected String doInBackground(String... params) {
			String strResult;
			try {
				// 处理后台执行的任务，在后台线程执行
				JSONObject param = new JSONObject();
				param.put("LottID", params[0]);
				// 设置请求action
				String action = params[1];
				// 获取请求返回值
				strResult = GetRequestParams.getRequestResult(param.toString(), action, getApplicationContext());
				return strResult;
			} catch (Exception e) {
				// TODO: handle exception
				Log.e("error", e.toString());
				return null;
			}
		}

		// 3.进度更新
		protected void onProgressUpdate(Integer... progress) {
		}

		// 4.完成后台任务
		protected void onPostExecute(String result) {
			if (result != null) {
				// Toast.LENGTH_LONG).show();
				try {
					JSONTokener jsonParser = new JSONTokener(result);
					JSONObject js = (JSONObject) jsonParser.nextValue();
					// 接下来的就是JSON对象的操作了
					if (Integer.parseInt(js.getString("Code")) == 0) {
						if (!"".equals(js.getString("Data"))) {
							kjData = getData(result);
							for (int i = 0; i < kjData.size(); i++) {
								String issue = kjData.get(i).get("Issue").toString();
								issue += "期";// = "期\t开奖号码"
								kjData.get(i).put("Issue", issue);
								String winNumber = kjData.get(i).get("WinNumber").toString();
								String[] nums = winNumber.split("\\+");
								// kjData.get(i).put("Ball", nums[0]);
								kjData.get(i).put("Ball", nums[0].replaceAll(",", " "));
								kjData.get(i).put("BlueBall", nums.length > 1 ? nums[1].trim() : "");
							}
							// KjInfoListAdapter adapter = new
							// KjInfoListAdapter(ElvYunDJActivity.this, mData);
							// buy_11x5_lv_kaijiang.setAdapter(adapter);
						} else {
						}
						// showdialog.closeDialog();
					} else {
					}
				} catch (JSONException ex) {
					// 异常处理代码
					Log.e("error", ex.toString());
				} finally {
					// showdialog.closeDialog();
				}
			} else {
			}
		}

		// 5.完成后操作
		protected void onCancelled() {
		}

	}

	private List<Map<String, Object>> getData(String strResult) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		try {
			JSONTokener jsonParser = new JSONTokener(strResult);
			JSONObject js = (JSONObject) jsonParser.nextValue();
			list = ConvertJsonToList.getList(js.getString("Data"));
		} catch (JSONException ex) {
			// 异常处理代码
			// ex.printStackTrace();
		}

		return list;
	}

	private Map<String, Object> getCurrentData(String strResult, String key) {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			JSONTokener jsonParser = new JSONTokener(strResult);
			JSONObject js = (JSONObject) jsonParser.nextValue();
			map = ConvertJsonToList.getMap(js.getString(key));
		} catch (JSONException ex) {
			// 异常处理代码
			// ex.printStackTrace();
		}

		return map;
	}

	private long setEndTime(Map<String, Object> data) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		long endTime = 0;
		try {
			long a = sdf.parse(data.get("CurrentTime").toString()).getTime();
			long b = sdf.parse(data.get("EndTime").toString()).getTime();
			endTime = (b - a) / 1000;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			// e.printStackTrace();
		}
		return endTime;
	}

	private void initView() {
		buy_ssq_llfoot0 = (LinearLayout) findViewById(R.id.buy_ssq_llfoot0);
		buy_ssq_rlfoot1 = (RelativeLayout) findViewById(R.id.buy_ssq_rlfoot1);
		buy_ssqxh_llxiala = (LinearLayout) findViewById(R.id.buy_ssqxh_llxiala);
		buy_ssqxh_ll10kjdetail = (LinearLayout) findViewById(R.id.buy_ssqxh_ll10kjdetail);
		buy_ssq_llfoot0.setVisibility(View.VISIBLE);
		buy_ssq_rlfoot1.setVisibility(View.GONE);
		// 改变第一个框的背景，得到该对象
		buy_11x5_first_num = (LinearLayout) findViewById(R.id.buy_11x5_first_num);
		buy_11x5_first_text_layout = (LinearLayout) findViewById(R.id.buy_11x5_first_num_text_layout);
		buy_11x5_2nd_num = (LinearLayout) findViewById(R.id.buy_11x5_2nd_num);
		buy_11x5_3rd_num = (LinearLayout) findViewById(R.id.buy_11x5_3rd_num);
		buy_11x5_1st_llnote = (LinearLayout) findViewById(R.id.buy_11x5_1st_llnote);
		buy_23_line = (View) findViewById(R.id.buy_23_line);
		// 初始化球
		initBall();
		// 初始化文本框
		initText();

		// 初始化button
		initButton();

		// 初始化下拉框
		initSelectPlayTypeView();
	}

	public void initBall() {
		// 初始化球
		init1stBall();

		// 初始化第2位球
		init2ndBall();

		// 初始化第3位球
		init3rdBall();
	}

	/**
	 * 机选及晃动手机
	 */
	public void initRandomBall() {
		initBall();
		ball_1st_dintInt = new DynArrayInt();
		ball_2nd_dintInt = new DynArrayInt();
		ball_3rd_dintInt = new DynArrayInt();

		ball_2nd_dintInt.removeAll();
		ball_3rd_dintInt.removeAll();
		ball_1st_dintInt.removeAll();

		if (playTypeId == 6210) {
			randomDirectThree();
			buy_23_line.setVisibility(View.VISIBLE);
			buy_11x5_first_text_layout.setVisibility(View.VISIBLE);
			buy_11x5_1st_llnote.setVisibility(View.GONE);
		} else if (playTypeId == 6209) {
			randomDirectTwo();
			buy_23_line.setVisibility(View.GONE);
			buy_11x5_first_text_layout.setVisibility(View.VISIBLE);
			buy_11x5_1st_llnote.setVisibility(View.GONE);
		} else {
			buy_23_line.setVisibility(View.GONE);
			buy_11x5_first_text_layout.setVisibility(View.GONE);
			buy_11x5_1st_llnote.setVisibility(View.VISIBLE);
			// 开始随机号码
			int ball_random[] = RandomGenData(1, 11, getRandomNum(playTypeId), "first");
			// 追加数组到ball_1st_dintInt中
			ball_1st_dintInt.addInt(ball_random);
		}
		getMoneyInfo();
	}

	public String randomDirectTwo() {
		String ball = "";
		int first_ball[] = RandomGenData(1, 11, 1, "first");
		int second_ball[] = RandomGenData(1, 11, 1, "second");
		// 判断是否有重复数字
		if (first_ball[0] == second_ball[0]) {
			initBall();
			randomDirectTwo();
		} else {
			ball_1st_dintInt = new DynArrayInt();
			ball_2nd_dintInt = new DynArrayInt();

			ball_1st_dintInt.addInt(first_ball);
			ball_2nd_dintInt.addInt(second_ball);
			String first = ball_1st_dintInt.getIntToString(0);
			String second = ball_2nd_dintInt.getIntToString(0);
			ball = first + "|" + second;
		}
		return ball;
	}

	public String randomDirectThree() {
		String ball = "";
		int first_ball[] = RandomGenData(1, 11, 1, "first");
		int second_ball[] = RandomGenData(1, 11, 1, "second");
		int third_ball[] = RandomGenData(1, 11, 1, "third");
		// 判断是否有重复数字
		if (first_ball[0] == second_ball[0] || second_ball[0] == third_ball[0] || third_ball[0] == first_ball[0]) {
			initBall();
			randomDirectThree();
		} else {
			ball_1st_dintInt = new DynArrayInt();
			ball_2nd_dintInt = new DynArrayInt();
			ball_3rd_dintInt = new DynArrayInt();

			ball_1st_dintInt.addInt(first_ball);
			ball_2nd_dintInt.addInt(second_ball);
			ball_3rd_dintInt.addInt(third_ball);

			String first = ball_1st_dintInt.getIntToString(0);
			String second = ball_2nd_dintInt.getIntToString(0);
			String third = ball_3rd_dintInt.getIntToString(0);
			ball = first + "|" + second + "|" + third;
		}
		return ball;
	}

	// 随机取球，并显示
	public int[] RandomGenData(int min, int max, int num, String position) {
		int[] temp;
		Random rndNumber;
		rndNumber = new Random();
		temp = new int[num];
		List<Integer> a1 = new ArrayList<Integer>();

		for (int i = min; i <= max; i++) {
			a1.add((Integer) i);

		}
		for (int i = 0; i < num; i++) {
			int index = rndNumber.nextInt(max - min + 1 - i);
			Object o = a1.get(index);
			temp[i] = ((Integer) o).intValue();
			if (position.equals("first"))
				BallRandom(1, 0, 0, temp[i]);
			if (position.equals("second"))
				BallRandom(0, 1, 0, temp[i]);
			if (position.equals("third"))
				BallRandom(0, 0, 1, temp[i]);
			a1.remove(index);
		}
		Arrays.sort(temp);
		return temp;
	}

	// 显示注数和金钱
	public void getMoneyInfo() {
		int money;
		count = 0;
		switch (playTypeId) {
		case 6210:
			buy_11x5_first_text_layout.setVisibility(View.VISIBLE);
			buy_11x5_1st_llnote.setVisibility(View.GONE);
			buy_23_line.setVisibility(View.VISIBLE);
			for (int a : ball_1st_dintInt.getAllInt()) {
				for (int b : ball_2nd_dintInt.getAllInt()) {
					if (a != b) {
						for (int c : ball_3rd_dintInt.getAllInt()) {
							if (c != b && c != a) {
								count++;
							}
						}
					}
				}
			}
			break;
		case 6209:
			buy_11x5_first_text_layout.setVisibility(View.VISIBLE);
			buy_11x5_1st_llnote.setVisibility(View.GONE);
			buy_23_line.setVisibility(View.GONE);
			for (int a : ball_1st_dintInt.getAllInt()) {
				for (int b : ball_2nd_dintInt.getAllInt()) {
					if (a != b) {
						count++;
					}
				}
			}
			break;
		default:
			buy_23_line.setVisibility(View.GONE);
			float ball_count = FactoryNum.ElvYDJ_Result(ball_1st_dintInt.getSize(), playTypeId);
			count = (int) (ball_count + 1.0e-6);
			break;
		}
		money = count * 2;
		allMoney = money;
		countText.setText(count + "");
		moneyText.setText(Html.fromHtml("<font color='#fe5052'>"+money+"</font>" + " 彩豆"));

		// 计算总奖金
		// 奖金
		int totalmoney = Kuai3Util.get11ydjMoney(playTypeId);
		prizeIntellChase = totalmoney;
		if (money == 0) {
			tvJiangJin.setText(context.getString(R.string.buy_show_jiangjin));
		} else {
			String strjiangjin = ".若中奖：奖金" + totalmoney + "彩豆，盈利" + (totalmoney - money) + "彩豆";
			tvJiangJin.setText(strjiangjin);
		}
		if (count == 0) {
			buy_ssq_llfoot0.setVisibility(View.VISIBLE);
			buy_ssq_rlfoot1.setVisibility(View.GONE);
		} else {
			buy_ssq_llfoot0.setVisibility(View.GONE);
			buy_ssq_rlfoot1.setVisibility(View.VISIBLE);
		}
	}

	public void BallRandom(int a, int b, int c, int num) {
		if (num == 1 && a == 1) {
			imButton01.setSelected(true);
		}
		if (num == 2 && a == 1) {
			imButton02.setSelected(true);
		}
		if (num == 3 && a == 1) {
			imButton03.setSelected(true);
		}
		if (num == 4 && a == 1) {
			imButton04.setSelected(true);
		}
		if (num == 5 && a == 1) {
			imButton05.setSelected(true);
		}
		if (num == 6 && a == 1) {
			imButton06.setSelected(true);
		}
		if (num == 7 && a == 1) {
			imButton07.setSelected(true);
		}
		if (num == 8 && a == 1) {
			imButton08.setSelected(true);
		}
		if (num == 9 && a == 1) {
			imButton09.setSelected(true);
		}
		if (num == 10 && a == 1) {
			imButton10.setSelected(true);
		}
		if (num == 11 && a == 1) {
			imButton11.setSelected(true);
		}

		if (num == 1 && b == 1) {
			imButtonb_01.setSelected(true);

		}
		if (num == 2 && b == 1) {
			imButtonb_02.setSelected(true);
		}
		if (num == 3 && b == 1) {
			imButtonb_03.setSelected(true);
		}
		if (num == 4 && b == 1) {
			imButtonb_04.setSelected(true);
		}
		if (num == 5 && b == 1) {
			imButtonb_05.setSelected(true);
		}
		if (num == 6 && b == 1) {
			imButtonb_06.setSelected(true);
		}
		if (num == 7 && b == 1) {
			imButtonb_07.setSelected(true);
		}
		if (num == 8 && b == 1) {
			imButtonb_08.setSelected(true);
		}
		if (num == 9 && b == 1) {
			imButtonb_09.setSelected(true);
		}
		if (num == 10 && b == 1) {
			imButtonb_10.setSelected(true);
		}
		if (num == 11 && b == 1) {
			imButtonb_11.setSelected(true);
		}
		if (num == 1 && c == 1) {
			imButtonc_01.setSelected(true);
		}
		if (num == 2 && c == 1) {
			imButtonc_02.setSelected(true);
		}
		if (num == 3 && c == 1) {
			imButtonc_03.setSelected(true);
		}
		if (num == 4 && c == 1) {
			imButtonc_04.setSelected(true);
		}
		if (num == 5 && c == 1) {
			imButtonc_05.setSelected(true);
		}
		if (num == 6 && c == 1) {
			imButtonc_06.setSelected(true);
		}
		if (num == 7 && c == 1) {
			imButtonc_07.setSelected(true);
		}
		if (num == 8 && c == 1) {
			imButtonc_08.setSelected(true);
		}
		if (num == 9 && c == 1) {
			imButtonc_09.setSelected(true);
		}
		if (num == 10 && c == 1) {
			imButtonc_10.setSelected(true);
		}
		if (num == 11 && c == 1) {
			imButtonc_11.setSelected(true);
		}
	}

	private int getRandomNum(int typeId) {
		int num = 0;
		switch (typeId) {
		case 6201:
			num = 1;
			break;
		case 6202:
		case 6211:
			num = 2;
			break;
		case 6203:
		case 6212:
			num = 3;
			break;
		case 6204:
			num = 4;
			break;
		case 6205:
			num = 5;
			break;
		case 6206:
			num = 6;
			break;
		case 6207:
			num = 7;
			break;
		case 6208:
			num = 8;
			break;
		}
		return num;
	}

	// Button初始化
	public void initButton() {
		buy_ssqxh_Button03 = (LinearLayout) findViewById(R.id.buy_ssqxh_Button03);
		buy_ssqxh_Button04 = (LinearLayout) findViewById(R.id.buy_ssqxh_Button04);
		buy_11x5_random = (Button) findViewById(R.id.buy_11x5_random);// 机选
		buy_11x5_clear = (Button) findViewById(R.id.buy_11x5_clear);// 清空选择
		buy_11x5_submit = (Button) findViewById(R.id.buy_11x5_submit);// 确认选择
	}

	private void initText() {
		currentIssue = (TextView) findViewById(R.id.buy_11x5_currentissue);
		endTimeText = (TextView) findViewById(R.id.buy_11x5_endtime);
		endTimeText.setText("--------------");
		// modeDES = (TextView) findViewById(R.id.buy_11x5_mode_des);
		countText = (TextView) findViewById(R.id.buy_11x5_count);
		moneyText = (TextView) findViewById(R.id.buy_11x5_amount);
		buy_11x5_1st_tvnote = (TextView) findViewById(R.id.buy_11x5_1st_tvnote);
		// currentIssue.setText(mData.get("IssueName").toString());
		// endTime.setText(mData.get("EndTime").toString());
		tvJiangJin = (TextView) findViewById(R.id.tvJiangJin);
	}

	/**
	 * 初始化任选说明文本框:6201 任选1 6202 任选2 6203 任选3 6204 任选4 6205 任选5 6206 任选6 6207 任选7
	 * 6208任选8 6209 前二直选 6210 前三直选 6211 前二组选 6212前三组选
	 */
	private void initRenXuanNoteText() {
		switch (playTypeId) {
		case 6201:
			buy_11x5_1st_tvnote.setText(Html.fromHtml("至少选<font color = '#fe5052'>"+1+"</font>个号码"));
			break;
		case 6202:
		case 6211:
			buy_11x5_1st_tvnote.setText(Html.fromHtml("至少选<font color = '#fe5052'>"+2+"</font>个号码"));
			break;
		case 6203:
		case 6212:
			buy_11x5_1st_tvnote.setText(Html.fromHtml("至少选<font color = '#fe5052'>"+3+"</font>个号码"));
			break;
		case 6204:
			buy_11x5_1st_tvnote.setText(Html.fromHtml("至少选<font color = '#fe5052'>"+4+"</font>个号码"));
			break;
		case 6205:
			buy_11x5_1st_tvnote.setText(Html.fromHtml("至少选<font color = '#fe5052'>"+5+"</font>个号码"));
			break;
		case 6206:
			buy_11x5_1st_tvnote.setText(Html.fromHtml("至少选<font color = '#fe5052'>"+6+"</font>个号码"));
			break;
		case 6207:
			buy_11x5_1st_tvnote.setText(Html.fromHtml("至少选<font color = '#fe5052'>"+7+"</font>个号码"));
			break;
		case 6208:
			buy_11x5_1st_tvnote.setText(Html.fromHtml("至少选<font color = '#fe5052'>"+8+"</font>个号码"));
			break;
		}
	}

	public void init1stBall() {
		ball_1st_dintInt = new DynArrayInt();

		imButton01 = (Button) findViewById(R.id.buy_11x5_imageButton01);
		imButton01.setSelected(false);
		imButton01.setText("01");
		imButton01.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButton01.isSelected()) {
					imButton01.setSelected(false);
					ball_1st_dintInt.remove(1);

				} else {
					imButton01.setSelected(true);
					ball_1st_dintInt.addInt(1);

				}
				getMoneyInfo();
			}
		});

		imButton02 = (Button) findViewById(R.id.buy_11x5_imageButton02);
		imButton02.setSelected(false);
		imButton02.setText("02");
		imButton02.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButton02.isSelected()) {
					imButton02.setSelected(false);
					ball_1st_dintInt.remove(2);

				} else {
					imButton02.setSelected(true);
					ball_1st_dintInt.addInt(2);

				}
				getMoneyInfo();
			}
		});

		imButton03 = (Button) findViewById(R.id.buy_11x5_imageButton03);
		imButton03.setSelected(false);
		imButton03.setText("03");
		imButton03.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButton03.isSelected()) {
					imButton03.setSelected(false);
					ball_1st_dintInt.remove(3);

				} else {
					imButton03.setSelected(true);
					ball_1st_dintInt.addInt(3);

				}
				getMoneyInfo();
			}
		});

		imButton04 = (Button) findViewById(R.id.buy_11x5_imageButton04);
		imButton04.setSelected(false);
		imButton04.setText("04");
		imButton04.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButton04.isSelected()) {
					imButton04.setSelected(false);
					ball_1st_dintInt.remove(4);

				} else {
					imButton04.setSelected(true);
					ball_1st_dintInt.addInt(4);

				}
				getMoneyInfo();
			}
		});
		imButton05 = (Button) findViewById(R.id.buy_11x5_imageButton05);
		imButton05.setSelected(false);
		imButton05.setText("05");
		imButton05.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButton05.isSelected()) {
					imButton05.setSelected(false);
					ball_1st_dintInt.remove(5);

				} else {
					imButton05.setSelected(true);
					ball_1st_dintInt.addInt(5);

				}
				getMoneyInfo();
			}
		});

		imButton06 = (Button) findViewById(R.id.buy_11x5_imageButton06);
		imButton06.setSelected(false);
		imButton06.setText("06");
		imButton06.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButton06.isSelected()) {
					imButton06.setSelected(false);
					ball_1st_dintInt.remove(6);

				} else {
					imButton06.setSelected(true);
					ball_1st_dintInt.addInt(6);

				}
				getMoneyInfo();
			}
		});

		imButton07 = (Button) findViewById(R.id.buy_11x5_imageButton07);
		imButton07.setSelected(false);
		imButton07.setText("07");
		imButton07.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButton07.isSelected()) {
					imButton07.setSelected(false);
					ball_1st_dintInt.remove(7);

				} else {
					imButton07.setSelected(true);
					ball_1st_dintInt.addInt(7);

				}
				getMoneyInfo();
			}
		});

		imButton08 = (Button) findViewById(R.id.buy_11x5_imageButton08);
		imButton08.setSelected(false);
		imButton08.setText("08");
		imButton08.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButton08.isSelected()) {
					imButton08.setSelected(false);
					ball_1st_dintInt.remove(8);

				} else {
					imButton08.setSelected(true);
					ball_1st_dintInt.addInt(8);

				}
				getMoneyInfo();
			}
		});

		imButton09 = (Button) findViewById(R.id.buy_11x5_imageButton09);
		imButton09.setSelected(false);
		imButton09.setText("09");
		imButton09.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButton09.isSelected()) {
					imButton09.setSelected(false);
					ball_1st_dintInt.remove(9);

				} else {
					imButton09.setSelected(true);
					ball_1st_dintInt.addInt(9);

				}
				getMoneyInfo();
			}
		});

		imButton10 = (Button) findViewById(R.id.buy_11x5_imageButton10);
		imButton10.setSelected(false);
		imButton10.setText("10");
		imButton10.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButton10.isSelected()) {
					imButton10.setSelected(false);
					ball_1st_dintInt.remove(10);

				} else {
					imButton10.setSelected(true);
					ball_1st_dintInt.addInt(10);

				}
				getMoneyInfo();
			}
		});

		imButton11 = (Button) findViewById(R.id.buy_11x5_imageButton11);
		imButton11.setSelected(false);
		imButton11.setText("11");
		imButton11.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButton11.isSelected()) {
					imButton11.setSelected(false);
					ball_1st_dintInt.remove(11);

				} else {
					imButton11.setSelected(true);
					ball_1st_dintInt.addInt(11);

				}
				getMoneyInfo();
			}
		});

	}

	public void init2ndBall() {
		ball_2nd_dintInt = new DynArrayInt();

		imButtonb_01 = (Button) findViewById(R.id.buy_11x5_b_01);
		imButtonb_01.setSelected(false);
		imButtonb_01.setText("01");
		imButtonb_01.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonb_01.isSelected()) {
					imButtonb_01.setSelected(false);
					ball_2nd_dintInt.remove(1);

				} else {
					imButtonb_01.setSelected(true);
					ball_2nd_dintInt.addInt(1);

				}
				getMoneyInfo();
			}
		});

		imButtonb_02 = (Button) findViewById(R.id.buy_11x5_b_02);
		imButtonb_02.setSelected(false);
		imButtonb_02.setText("02");
		imButtonb_02.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonb_02.isSelected()) {
					imButtonb_02.setSelected(false);
					ball_2nd_dintInt.remove(2);

				} else {
					imButtonb_02.setSelected(true);
					ball_2nd_dintInt.addInt(2);

				}
				getMoneyInfo();
			}
		});

		imButtonb_03 = (Button) findViewById(R.id.buy_11x5_b_03);
		imButtonb_03.setSelected(false);
		imButtonb_03.setText("03");
		imButtonb_03.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonb_03.isSelected()) {
					imButtonb_03.setSelected(false);
					ball_2nd_dintInt.remove(3);

				} else {
					imButtonb_03.setSelected(true);
					ball_2nd_dintInt.addInt(3);

				}
				getMoneyInfo();
			}
		});

		imButtonb_04 = (Button) findViewById(R.id.buy_11x5_b_04);
		imButtonb_04.setSelected(false);
		imButtonb_04.setText("04");
		imButtonb_04.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonb_04.isSelected()) {
					imButtonb_04.setSelected(false);
					ball_2nd_dintInt.remove(4);

				} else {
					imButtonb_04.setSelected(true);
					ball_2nd_dintInt.addInt(4);

				}
				getMoneyInfo();
			}
		});

		imButtonb_05 = (Button) findViewById(R.id.buy_11x5_b_05);
		imButtonb_05.setSelected(false);
		imButtonb_05.setText("05");
		imButtonb_05.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonb_05.isSelected()) {
					imButtonb_05.setSelected(false);
					ball_2nd_dintInt.remove(5);

				} else {
					imButtonb_05.setSelected(true);
					ball_2nd_dintInt.addInt(5);

				}
				getMoneyInfo();
			}
		});

		imButtonb_06 = (Button) findViewById(R.id.buy_11x5_b_06);
		imButtonb_06.setSelected(false);
		imButtonb_06.setText("06");
		imButtonb_06.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonb_06.isSelected()) {
					imButtonb_06.setSelected(false);
					ball_2nd_dintInt.remove(6);

				} else {
					imButtonb_06.setSelected(true);
					ball_2nd_dintInt.addInt(6);

				}
				getMoneyInfo();
			}
		});

		imButtonb_07 = (Button) findViewById(R.id.buy_11x5_b_07);
		imButtonb_07.setSelected(false);
		imButtonb_07.setText("07");
		imButtonb_07.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonb_07.isSelected()) {
					imButtonb_07.setSelected(false);
					ball_2nd_dintInt.remove(7);

				} else {
					imButtonb_07.setSelected(true);
					ball_2nd_dintInt.addInt(7);

				}
				getMoneyInfo();
			}
		});

		imButtonb_08 = (Button) findViewById(R.id.buy_11x5_b_08);
		imButtonb_08.setSelected(false);
		imButtonb_08.setText("08");
		imButtonb_08.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonb_08.isSelected()) {
					imButtonb_08.setSelected(false);
					ball_2nd_dintInt.remove(8);

				} else {
					imButtonb_08.setSelected(true);
					ball_2nd_dintInt.addInt(8);

				}
				getMoneyInfo();
			}
		});

		imButtonb_09 = (Button) findViewById(R.id.buy_11x5_b_09);
		imButtonb_09.setSelected(false);
		imButtonb_09.setText("09");
		imButtonb_09.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonb_09.isSelected()) {
					imButtonb_09.setSelected(false);
					ball_2nd_dintInt.remove(9);

				} else {
					imButtonb_09.setSelected(true);
					ball_2nd_dintInt.addInt(9);

				}
				getMoneyInfo();
			}
		});

		imButtonb_10 = (Button) findViewById(R.id.buy_11x5_b_10);
		imButtonb_10.setSelected(false);
		imButtonb_10.setText("10");
		imButtonb_10.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonb_10.isSelected()) {
					imButtonb_10.setSelected(false);
					ball_2nd_dintInt.remove(10);

				} else {
					imButtonb_10.setSelected(true);
					ball_2nd_dintInt.addInt(10);

				}
				getMoneyInfo();
			}
		});

		imButtonb_11 = (Button) findViewById(R.id.buy_11x5_b_11);
		imButtonb_11.setSelected(false);
		imButtonb_11.setText("11");
		imButtonb_11.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonb_11.isSelected()) {
					imButtonb_11.setSelected(false);
					ball_2nd_dintInt.remove(11);

				} else {
					imButtonb_11.setSelected(true);
					ball_2nd_dintInt.addInt(11);

				}
				getMoneyInfo();
			}
		});
	}

	public void init3rdBall() {
		ball_3rd_dintInt = new DynArrayInt();

		imButtonc_01 = (Button) findViewById(R.id.buy_11x5_c_01);
		imButtonc_01.setSelected(false);
		imButtonc_01.setText("01");
		imButtonc_01.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonc_01.isSelected()) {
					imButtonc_01.setSelected(false);
					ball_3rd_dintInt.remove(1);

				} else {
					imButtonc_01.setSelected(true);
					ball_3rd_dintInt.addInt(1);

				}
				getMoneyInfo();
			}
		});

		imButtonc_02 = (Button) findViewById(R.id.buy_11x5_c_02);
		imButtonc_02.setSelected(false);
		imButtonc_02.setText("02");
		imButtonc_02.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonc_02.isSelected()) {
					imButtonc_02.setSelected(false);
					ball_3rd_dintInt.remove(2);

				} else {
					imButtonc_02.setSelected(true);
					ball_3rd_dintInt.addInt(2);

				}
				getMoneyInfo();
			}
		});

		imButtonc_03 = (Button) findViewById(R.id.buy_11x5_c_03);
		imButtonc_03.setSelected(false);
		imButtonc_03.setText("03");
		imButtonc_03.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonc_03.isSelected()) {
					imButtonc_03.setSelected(false);
					ball_3rd_dintInt.remove(3);

				} else {
					imButtonc_03.setSelected(true);
					ball_3rd_dintInt.addInt(3);

				}
				getMoneyInfo();
			}
		});

		imButtonc_04 = (Button) findViewById(R.id.buy_11x5_c_04);
		imButtonc_04.setSelected(false);
		imButtonc_04.setText("04");
		imButtonc_04.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonc_04.isSelected()) {
					imButtonc_04.setSelected(false);
					ball_3rd_dintInt.remove(4);

				} else {
					imButtonc_04.setSelected(true);
					ball_3rd_dintInt.addInt(4);

				}
				getMoneyInfo();
			}
		});

		imButtonc_05 = (Button) findViewById(R.id.buy_11x5_c_05);
		imButtonc_05.setSelected(false);
		imButtonc_05.setText("05");
		imButtonc_05.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonc_05.isSelected()) {
					imButtonc_05.setSelected(false);
					ball_3rd_dintInt.remove(5);

				} else {
					imButtonc_05.setSelected(true);
					ball_3rd_dintInt.addInt(5);

				}
				getMoneyInfo();
			}
		});

		imButtonc_06 = (Button) findViewById(R.id.buy_11x5_c_06);
		imButtonc_06.setSelected(false);
		imButtonc_06.setText("06");
		imButtonc_06.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonc_06.isSelected()) {
					imButtonc_06.setSelected(false);
					ball_3rd_dintInt.remove(6);

				} else {
					imButtonc_06.setSelected(true);
					ball_3rd_dintInt.addInt(6);

				}
				getMoneyInfo();
			}
		});
		imButtonc_07 = (Button) findViewById(R.id.buy_11x5_c_07);
		imButtonc_07.setSelected(false);
		imButtonc_07.setText("07");
		imButtonc_07.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonc_07.isSelected()) {
					imButtonc_07.setSelected(false);
					ball_3rd_dintInt.remove(7);

				} else {
					imButtonc_07.setSelected(true);
					ball_3rd_dintInt.addInt(7);

				}
				getMoneyInfo();
			}
		});

		imButtonc_08 = (Button) findViewById(R.id.buy_11x5_c_08);
		imButtonc_08.setSelected(false);
		imButtonc_08.setText("08");
		imButtonc_08.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonc_08.isSelected()) {
					imButtonc_08.setSelected(false);
					ball_3rd_dintInt.remove(8);

				} else {
					imButtonc_08.setSelected(true);
					ball_3rd_dintInt.addInt(8);

				}
				getMoneyInfo();
			}
		});

		imButtonc_09 = (Button) findViewById(R.id.buy_11x5_c_09);
		imButtonc_09.setSelected(false);
		imButtonc_09.setText("09");
		imButtonc_09.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonc_09.isSelected()) {
					imButtonc_09.setSelected(false);
					ball_3rd_dintInt.remove(9);

				} else {
					imButtonc_09.setSelected(true);
					ball_3rd_dintInt.addInt(9);

				}
				getMoneyInfo();
			}
		});

		imButtonc_10 = (Button) findViewById(R.id.buy_11x5_c_10);
		imButtonc_10.setSelected(false);
		imButtonc_10.setText("10");
		imButtonc_10.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonc_10.isSelected()) {
					imButtonc_10.setSelected(false);
					ball_3rd_dintInt.remove(10);

				} else {
					imButtonc_10.setSelected(true);
					ball_3rd_dintInt.addInt(10);

				}
				getMoneyInfo();
			}
		});

		imButtonc_11 = (Button) findViewById(R.id.buy_11x5_c_11);
		imButtonc_11.setSelected(false);
		imButtonc_11.setText("11");
		imButtonc_11.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (imButtonc_11.isSelected()) {
					imButtonc_11.setSelected(false);
					ball_3rd_dintInt.remove(11);

				} else {
					imButtonc_11.setSelected(true);
					ball_3rd_dintInt.addInt(11);

				}
				getMoneyInfo();
			}
		});
	}

	/**
	 * 初始化头部菜单玩法选择视图
	 */
	public void initSelectPlayTypeView() {
		initBall();
		initRenXuanNoteText();
		allMoney = 0;
		count = 0;
		countText.setText(0 + "");
		moneyText.setText(0 + "");
		tvJiangJin.setText(context.getString(R.string.buy_show_jiangjin));
		TextView top_title_tvplaytype = (TextView) findViewById(R.id.top_title_tvplaytype);
		top_title_tvplaytype.setText(strPlayType);
		switch (playTypeId) {
		case 6210:
			buy_11x5_2nd_num.setVisibility(View.VISIBLE);
			buy_11x5_3rd_num.setVisibility(View.VISIBLE);
			buy_23_line.setVisibility(View.VISIBLE);
			buy_11x5_first_text_layout.setVisibility(View.VISIBLE);
			buy_11x5_1st_llnote.setVisibility(View.GONE);
			break;
		case 6209:
			buy_11x5_3rd_num.setVisibility(View.GONE);
			buy_11x5_2nd_num.setVisibility(View.VISIBLE);
			buy_11x5_1st_llnote.setVisibility(View.GONE);
			buy_23_line.setVisibility(View.GONE);
			buy_11x5_first_text_layout.setVisibility(View.VISIBLE);
			break;
		default:
			buy_11x5_2nd_num.setVisibility(View.GONE);
			buy_11x5_3rd_num.setVisibility(View.GONE);
			buy_11x5_1st_llnote.setVisibility(View.VISIBLE);
			buy_23_line.setVisibility(View.GONE);
			buy_11x5_first_text_layout.setVisibility(View.GONE);
			break;
		}
	}

	/**
	 * 菜单玩法按钮事件
	 * 
	 * @param btnId
	 */
	private void setBtnOnClick(final int btnId) {
		Button btn = (Button) menutypeview.findViewById(btnId);
		btn.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				menu_popupWindow.dismiss();
				setOrderField(btnId);
				if (ApplicationData.getInstance().getList_11x5dto().size() == 0
						&& ApplicationData.getInstance().getAll_11x5money() == 0
						&& ApplicationData.getInstance().getPlay_11x5Id() == 0) {
					initSelectPlayTypeView();
				} else {
					MyDialog.Builder dialog = new MyDialog.Builder(ElvYunDJActivity.this);
					dialog.setTitle("提示");
					dialog.setMessage("切换玩法将使之前所选号码清空，确认切换吗？");
					dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							ApplicationData.getInstance().initList();
							initSelectPlayTypeView();
							dialog.dismiss();
						}
					});
					dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							dialog.cancel();
						}
					});
					dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
						@Override
						public void onCancel(DialogInterface dialog) {
							// TODO Auto-generated method stub
							int app_playId = ApplicationData.getInstance().getPlay_11x5Id();
							// System.out.println("app_playId:" + app_playId +
							// "  playTypeId:" + playTypeId);
							if (app_playId == 6201) {
								playTypeId = 6201;
								strPlayType = "任选一";
							} else if (app_playId == 6202) {
								// playType.setSelection(1);
								playTypeId = 6202;
								strPlayType = "任选二";
							} else if (app_playId == 6203) {
								// playType.setSelection(2);
								playTypeId = 6203;
								strPlayType = "任选三";
							} else if (app_playId == 6204) {
								playTypeId = 6204;
								strPlayType = "任选四";
							} else if (app_playId == 6205) {
								playTypeId = 6205;
								strPlayType = "任选五";
							} else if (app_playId == 6206) {
								playTypeId = 6206;
								strPlayType = "任选六";
							} else if (app_playId == 6207) {
								playTypeId = 6207;
								strPlayType = "任选七";
							} else if (app_playId == 6208) {
								playTypeId = 6208;
								strPlayType = "任选八";
							} else if (app_playId == 6209) {
								playTypeId = 6209;
								strPlayType = "前二直选";
							} else if (app_playId == 6210) {
								playTypeId = 6210;
								strPlayType = "前三直选";
							} else if (app_playId == 6211) {
								playTypeId = 6211;
								strPlayType = "前二组选";
							} else if (app_playId == 6212) {
								playTypeId = 6212;
								strPlayType = "前三组选";
							}

						}
					});
					dialog.create().show();

				}
			}
		});
	}

	/**
	 * 获取玩法及改变按钮背景
	 * 
	 * @param btnId
	 */
	public void setOrderField(int btnId) {
		// 恢复默认
		((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button01)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button02)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button03)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button04)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button05)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button06)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button07)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button08)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button09)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button10)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button11)).setSelected(false);
		((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button12)).setSelected(false);
		// ((Button)
		// findViewById(R.id.hemai_main_btnJD)).setTextColor(context.getResources().getColor(R.color.black));
		switch (btnId) {
		case R.id.buy_new11x5_topmenulink_Button01:
			playTypeId = 6201;
			strPlayType = "任选一";
			((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button01)).setSelected(true);
			// ((Button)
			// findViewById(R.id.hemai_main_btnJD)).setTextColor(context.getResources().getColor(R.color.white));
			break;
		case R.id.buy_new11x5_topmenulink_Button02:
			playTypeId = 6202;
			strPlayType = "任选二";
			((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button02)).setSelected(true);
			break;
		case R.id.buy_new11x5_topmenulink_Button03:
			playTypeId = 6203;
			strPlayType = "任选三";
			((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button03)).setSelected(true);
			break;
		case R.id.buy_new11x5_topmenulink_Button04:
			playTypeId = 6204;
			strPlayType = "任选四";
			((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button04)).setSelected(true);
			break;
		case R.id.buy_new11x5_topmenulink_Button05:
			playTypeId = 6205;
			strPlayType = "任选五";
			((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button05)).setSelected(true);
			break;
		case R.id.buy_new11x5_topmenulink_Button06:
			playTypeId = 6206;
			strPlayType = "任选六";
			((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button06)).setSelected(true);
			break;
		case R.id.buy_new11x5_topmenulink_Button07:
			playTypeId = 6207;
			strPlayType = "任选七";
			((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button07)).setSelected(true);
			break;
		case R.id.buy_new11x5_topmenulink_Button08:
			playTypeId = 6208;
			strPlayType = "任选八";
			((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button08)).setSelected(true);
			break;
		case R.id.buy_new11x5_topmenulink_Button09:
			playTypeId = 6210;
			strPlayType = "前三直选";
			((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button09)).setSelected(true);
			break;
		case R.id.buy_new11x5_topmenulink_Button10:
			playTypeId = 6212;
			strPlayType = "前三组选";
			((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button10)).setSelected(true);
			break;
		case R.id.buy_new11x5_topmenulink_Button11:
			playTypeId = 6209;
			strPlayType = "前二直选";
			((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button11)).setSelected(true);
			break;
		case R.id.buy_new11x5_topmenulink_Button12:
			playTypeId = 6211;
			strPlayType = "前二组选";
			((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button12)).setSelected(true);
			break;
		}
	}

	// TitleBar标题栏
	public void TitleBar() {
		// Title信息(返回+Title)
		Button back = (Button) findViewById(R.id.top_title_back);
		back.getBackground().setAlpha(255);// 透明度0~255透明度值 ，值越小越透明
		back.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				onKeyDown(KeyEvent.KEYCODE_BACK, null);
			}
		});

		TextView tvinfo = (TextView) findViewById(R.id.top_title_info);
		tvinfo.setText(R.string.buy_new11ydj);

		// final RelativeLayout top_title_rlplaytype = (RelativeLayout)
		// findViewById(R.id.top_title_rlplaytype);
		final LinearLayout buy_jclq_center_rl2 = (LinearLayout) findViewById(R.id.buy_jclq_center_rl2);
		buy_jclq_center_rl2.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				LayoutInflater inflater = LayoutInflater.from(ElvYunDJActivity.this);
				// View menutypeview =
				// inflater.inflate(R.layout.buy_new11x5_topmenulink, null);
				menutypeview = inflater.inflate(R.layout.buy_new11x5_topmenulink, null);
				menu_popupWindow = new PopupWindow(menutypeview, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
				menu_popupWindow.setBackgroundDrawable(new BitmapDrawable());
				
				menu_popupWindow.setFocusable(true);
				menu_popupWindow.setTouchable(true);
				menu_popupWindow.setOutsideTouchable(false);
				
				menu_popupWindow.showAtLocation(menutypeview, Gravity.CENTER | Gravity.TOP, 0, 0);
				menu_popupWindow.showAsDropDown(buy_jclq_center_rl2);
				menutypeview.setOnClickListener(new View.OnClickListener() {
					public void onClick(View v) {
						// TODO Auto-generated method stub
						menu_popupWindow.dismiss();
					}
				});
				// 进度战绩总额按钮事件
				setBtnOnClick(R.id.buy_new11x5_topmenulink_Button01);
				setBtnOnClick(R.id.buy_new11x5_topmenulink_Button02);
				setBtnOnClick(R.id.buy_new11x5_topmenulink_Button03);
				setBtnOnClick(R.id.buy_new11x5_topmenulink_Button04);
				setBtnOnClick(R.id.buy_new11x5_topmenulink_Button05);
				setBtnOnClick(R.id.buy_new11x5_topmenulink_Button06);
				setBtnOnClick(R.id.buy_new11x5_topmenulink_Button07);
				setBtnOnClick(R.id.buy_new11x5_topmenulink_Button08);
				setBtnOnClick(R.id.buy_new11x5_topmenulink_Button09);
				setBtnOnClick(R.id.buy_new11x5_topmenulink_Button10);
				setBtnOnClick(R.id.buy_new11x5_topmenulink_Button11);
				setBtnOnClick(R.id.buy_new11x5_topmenulink_Button12);
				// Log.d("elv", "点击menu_popupWindow");
				// select first button
				if (playTypeId == 6201) {
					((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button01)).setSelected(true);
				} else if (playTypeId == 6202) {
					((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button02)).setSelected(true);
				} else if (playTypeId == 6203) {
					((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button03)).setSelected(true);
				} else if (playTypeId == 6204) {
					((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button04)).setSelected(true);
				} else if (playTypeId == 6205) {
					((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button05)).setSelected(true);
				} else if (playTypeId == 6206) {
					((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button06)).setSelected(true);
				} else if (playTypeId == 6207) {
					((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button07)).setSelected(true);
				} else if (playTypeId == 6208) {
					((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button08)).setSelected(true);
				} else if (playTypeId == 6210) {// 前三直选
					((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button09)).setSelected(true);
				} else if (playTypeId == 6212) {// 前三组选
					((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button10)).setSelected(true);
				} else if (playTypeId == 6209) {// 前二直选
					((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button11)).setSelected(true);
				} else if (playTypeId == 6211) {
					((Button) menutypeview.findViewById(R.id.buy_new11x5_topmenulink_Button12)).setSelected(true);
				}
			}
		});

		final Button refres = (Button) findViewById(R.id.top_title_refres);
		refres.setBackgroundDrawable(null);
		refres.setText("帮助");
		// refres.setBackgroundResource(R.color.common_menu);
		refres.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				LayoutInflater inflater = LayoutInflater.from(ElvYunDJActivity.this);
				View menuview = inflater.inflate(R.layout.public_menulink, null);
				m_popupWindow = new PopupWindow(menuview, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
				m_popupWindow.setBackgroundDrawable(new BitmapDrawable());
				m_popupWindow.setOutsideTouchable(true);
				m_popupWindow.showAtLocation(menuview, Gravity.RIGHT | Gravity.TOP, 0, 0);
				m_popupWindow.showAsDropDown(refres);

				menuview.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
					}
				});

				Button public_menulink_Button01 = (Button) menuview.findViewById(R.id.public_menulink_Button01);
				public_menulink_Button01.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
						Intent intent;
						if (checkUserLogin()) {
							Intent intent0 = new Intent();
							intent0.putExtra("lotID", LOT_ID_11YDJ);
							intent0.setClass(ElvYunDJActivity.this, BetRecordActivity.class);
							startActivity(intent0);
						} else {
							intent = new Intent(getApplicationContext(), LoginActivity.class);
							startActivityForResult(intent, REQ_CODE_ELV);
						}
					}
				});

				Button public_menulink_Button02 = (Button) menuview.findViewById(R.id.public_menulink_Button02);
				public_menulink_Button02.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
						Intent intent;
						if (checkUserLogin()) {
							intent = new Intent(getApplicationContext(), ZhRecordActivity.class);
							startActivity(intent);
						} else {
							intent = new Intent(getApplicationContext(), LoginActivity.class);
							startActivityForResult(intent, REQ_CODE_ELV);
						}
					}
				});
				Button public_menulink_Button03 = (Button) menuview.findViewById(R.id.public_menulink_Button03);
				public_menulink_Button03.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
						Intent intent;
						intent = new Intent(getApplicationContext(), KjinfoListByType.class);
						intent.putExtra("LottID", "62");
						intent.putExtra("LottName", getString(R.string.kjinfo_number_1_info));
						startActivity(intent);
					}
				});
				Button public_menulink_Button04 = (Button) menuview.findViewById(R.id.public_menulink_Button04);
				public_menulink_Button04.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						m_popupWindow.dismiss();
						// Intent intent = new Intent(getApplicationContext(),
						// HelpActivity.class);
						// startActivity(intent);
						Intent intent = new Intent(getApplicationContext(), CaiPiaoHelp.class);
						intent.putExtra("cp_title", "十一运夺金");
						intent.putExtra("cp_url", "syydj.html");
						startActivity(intent);
					}
				});
			}
		});
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		// m_popupWindow.dismiss();
		// return super.onTouchEvent(event);
		if (m_popupWindow != null) {
			m_popupWindow.dismiss();
		}
		if (menu_popupWindow != null) {
			menu_popupWindow.dismiss();
		}
		return super.onTouchEvent(event);
	}

	public boolean checkUserLogin() {
		// app_11x5dto = (ApplicationBall) getApplication();
		if (!ApplicationData.getInstance().getLoginName().equals("")
				&& !ApplicationData.getInstance().getLoginPwd().equals("")
				|| !ApplicationData.getInstance().getUserID().equals("")) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if (m_popupWindow != null) {
				m_popupWindow.dismiss();
			}
			if (menu_popupWindow != null) {
				menu_popupWindow.dismiss();
			}
			if (ifbacklist) {
				Intent intent = new Intent();
				intent.putExtra("list_elvdto", ApplicationData.getInstance().getList_11x5dto());
				intent.putExtra("PlayTypeID", playTypeId);
				intent.putExtra("PlayType", strPlayType);
				intent.putExtra("AllMoney", ApplicationData.getInstance().getAll_11x5money());
				intent.putExtra("LotID", lotID);
				intent.putExtra("Count", count);
				intent.putExtra("IssueID", issueID);
				intent.putExtra("IssueName", issueName);
				intent.putExtra("bs", bs);
				prizeIntellChase = getIntent().getIntExtra("prizeIntellChase", 0);
				//Log.d("van",prizeIntellChase +"--------" );
				intent.putExtra("prizeIntellChase",prizeIntellChase);
				intent.setClass(ElvYunDJActivity.this, ElvYunDJListActivity.class);
				startActivityForResult(intent, REQ_CODE_BUYMAIN);// (intent);
			} else {
				if(ifPush){
					Intent intent = new Intent(this, JddMainActivity.class);
					startActivity(intent);
				}
				ApplicationData.getInstance().initList();
			}
			this.finish();
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}

	};

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onActivityResult(int, int,
	 * android.content.Intent)
	 */
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		if (requestCode == REQ_CODE_BUYMAIN && resultCode == RESULT_OK) {
			onKeyDown(KeyEvent.KEYCODE_BACK, null);
		}
		if(resultCode == RESULT_OK) {
    if(requestCode == REQ_CODE_BUY_LOGIN ) {
			goXhlbSubmit();
		}
		}
	};

	private void goXhlbSubmit() {
		// TODO Auto-generated method stub

		// TODO Auto-generated method stub
		if (checkUserLogin()) {
			if (issueName == null || issueName.equals("")) {
				Toast.makeText(ElvYunDJActivity.this, R.string.is_retrieving_period_time, Toast.LENGTH_SHORT)
						.show();
				return;
			}
			if (!(allMoney == 0 || count == 0)) {
				BallDTO elvdto = new BallDTO();
				// 获得自定义的应用程序BallDTO
				// app_11x5dto = (ApplicationBall) getApplication();
				// 如果是直选三
				if (playTypeId == 6210) {
					buy_23_line.setVisibility(View.VISIBLE);
					buy_11x5_first_text_layout.setVisibility(View.VISIBLE);
					buy_11x5_1st_llnote.setVisibility(View.GONE);
					// 获取每位的长度
					int a = ball_1st_dintInt.getSize();
					int b = ball_2nd_dintInt.getSize();
					int c = ball_3rd_dintInt.getSize();
					String ball = "";
					if (a >= 1 && b >= 1 && c >= 1) {
						String first_ball = ball_1st_dintInt.getAllIntToString(ball_1st_dintInt.getAllInt());
						first_ball = first_ball.substring(0, first_ball.length() - 1);
						String second_ball = ball_2nd_dintInt.getAllIntToString(ball_2nd_dintInt.getAllInt());
						second_ball = second_ball.substring(0, second_ball.length() - 1);
						String third_ball = ball_3rd_dintInt.getAllIntToString(ball_3rd_dintInt.getAllInt());
						third_ball = third_ball.substring(0, third_ball.length() - 1);
						first_ball = DynArrayInt.sortBallDouble(first_ball);
						second_ball = DynArrayInt.sortBallDouble(second_ball);
						third_ball = DynArrayInt.sortBallDouble(third_ball);
						ball = first_ball + "|" + second_ball + "|" + third_ball;
						sendIntent(elvdto, ball);
					} else {
						Toast.makeText(ElvYunDJActivity.this, R.string.direct_elections_three,
								Toast.LENGTH_SHORT).show();
					}
				} else if (playTypeId == 6209) {
					int a = ball_1st_dintInt.getSize();
					int b = ball_2nd_dintInt.getSize();
					String ball = "";
					if (a >= 1 && b >= 1) {
						String first_ball = ball_1st_dintInt.getAllIntToString(ball_1st_dintInt.getAllInt());
						first_ball = first_ball.substring(0, first_ball.length() - 1);
						String second_ball = ball_2nd_dintInt.getAllIntToString(ball_2nd_dintInt.getAllInt());
						second_ball = second_ball.substring(0, second_ball.length() - 1);
						first_ball = DynArrayInt.sortBallDouble(first_ball);
						second_ball = DynArrayInt.sortBallDouble(second_ball);
						ball = first_ball + "|" + second_ball;
						sendIntent(elvdto, ball);
					} else {
						Toast.makeText(ElvYunDJActivity.this, R.string.direct_elections_two, Toast.LENGTH_SHORT)
								.show();
					}
				} else {
					if (ball_1st_dintInt.getSize() >= getRandomNum(playTypeId)) {
						// int[]数组中
						String ball = ball_1st_dintInt.getAllIntToString(ball_1st_dintInt.getAllInt());
						ball = ball.substring(0, ball.length() - 1);
						ball = DynArrayInt.sortBallDouble(ball);
						sendIntent(elvdto, ball);
					} else {
						Toast.makeText(ElvYunDJActivity.this, "至少选择" + getRandomNum(playTypeId) + "号码!",
								Toast.LENGTH_SHORT).show();
					}
				}
			} else {
				// if
				// (ApplicationData.getInstance().getList_11x5dto().size()
				// == 0) {
				Toast.makeText(ElvYunDJActivity.this, R.string.please_select_a_valid_bets_number,
						Toast.LENGTH_SHORT).show();
				// } else {
				// Intent intent = new Intent();
				// intent.putExtra("list_elvdto",
				// ApplicationData.getInstance().getList_11x5dto());
				// intent.putExtra("PlayTypeID", playTypeId);
				// intent.putExtra("PlayType", strPlayType);
				// intent.putExtra("AllMoney",
				// ApplicationData.getInstance().getAll_11x5money());
				// intent.putExtra("LotID", lotID);
				// intent.putExtra("Count", count);
				// intent.putExtra("IssueID", issueID);
				// intent.putExtra("IssueName", issueName);
				// intent.setClass(ElvYunDJActivity.this,
				// ElvYunDJListActivity.class);
				// startActivityForResult(intent,
				// REQ_CODE_BUYMAIN);//(intent);
				// }
			}
		} else {
			Intent intent = new Intent();
			intent.setClass(ElvYunDJActivity.this, LoginActivity.class);
			startActivityForResult(intent, REQ_CODE_BUY_LOGIN);
		}
	
	}

	class KjInfoListAdapter extends BaseAdapter {

		private LayoutInflater inflater = null;

		private List<Map<String, Object>> mData;

		public KjInfoListAdapter(Context context, List<Map<String, Object>> mData) {
			inflater = LayoutInflater.from(context);
			this.mData = mData;
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return mData.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(final int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			ViewHolder holder = null;
			holder = new ViewHolder();

			LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			layoutParams.gravity = Gravity.CENTER_VERTICAL;

			String redBTemp = mData.get(position).get("Ball").toString();
			String blueBTemp = mData.get(position).get("BlueBall").toString();

			convertView = inflater.inflate(R.layout.buy_new11x5_list_kaijiang, null);
			holder.name = (TextView) convertView.findViewById(R.id.kjinfo_main_list_type_title);
			holder.ballred = (TextView) convertView.findViewById(R.id.kjinfo_main_list_type_info);
			holder.ballblue = (TextView) convertView.findViewById(R.id.kjinfo_main_list_type_info_blue);
			holder.ballred.setText(redBTemp/*
											 * mData.get(position).get("Ball"
											 * ).toString()
											 */);
			holder.ballblue.setText(blueBTemp/*
											 * mData.get(position).get(
											 * "BlueBall").toString()
											 */);

			holder.name.setText(mData.get(position).get("Issue").toString());
			convertView.setTag(holder);
			return convertView;
		}

		class ViewHolder {
			TextView name;
			TextView ballred;
			TextView ballblue;
			LinearLayout ballLayout;
		}
	}

	@Override
	public void finish() {
		if (m_popupWindow != null) {
			m_popupWindow.dismiss();
		}
		if (menu_popupWindow != null) {
			menu_popupWindow.dismiss();
		}
		super.finish();
		SysApplication.getInstance().removeActivity(this);
	};

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		handler.removeCallbacks(runnable);
		super.onDestroy();
	}
}